<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";

// const user = {
//   id: 1,
//   username: '啵啵',
//   userAccount: '123456',
//   avatarUrl: 'https://img0.baidu.com/it/u=1479714859,2343991471&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1724950800&t=cd2e2a31bae1ae03a562fddc9d4c4fc9',
//   gender: '男',
//   phone: '123456789',
//   email: '12135@qq.com',
//   tags: ['java', 'c++', '大一'],
//   planetCode: '1234',
//   createTime: new Date(),
// };
const user = ref();
onMounted(async () => {
  user.value = await getCurrentUser();
})
const router = useRouter();

const doEdit = (editKey: string, editName: string, currentValue: string) => {
  console.log(editName)
  router.push({
        path: '/user/edit',
        query: {
          editKey,
          editName,
          currentValue,
        }
      }
  );
}

</script>

<template>
  <template v-if="user">
    <van-cell title="昵称" :value="user.username" @click="doEdit('username','昵称',user.username)" is-link
              to="/user/edit"/>
    <van-cell title="账户" :value="user.userAccount"/>
    <van-cell title="头像">
      <img style="height: 48px" :src="user.avatarUrl"/>
    </van-cell>
    <van-cell title="性别" :value="user.gender" @click="doEdit('gender','性别',user.gender)" is-link/>
    <van-cell title="电话" :value="user.phone" @click="doEdit('phone','电话',user.phone)" is-link/>
    <van-cell title="邮箱" :value="user.email" @click="doEdit('email','邮箱',user.email)" is-link/>
    <van-cell title="标签" :value="user.tags" @click="doEdit('tags','标签',user.tags)" is-link/>
    <van-cell title="星球编号" :value="user.planetCode"/>
    <van-cell title="创建时间" :value="user.createTime"/>
  </template>
</template>

<style scoped>

</style>